#ifndef LimitSingleInstance_H
#define LimitSingleInstance_H

#include <windows.h>

class CLimitSingleInstance{
protected:
	DWORD  m_dwLastError;
	HANDLE m_hMutex;

public:
	CLimitSingleInstance(LPCTSTR strMutexName){
		m_hMutex = CreateMutex(NULL, FALSE, strMutexName);
		m_dwLastError = GetLastError();
	}

	~CLimitSingleInstance(){
		if (m_hMutex){
			CloseHandle(m_hMutex);
			m_hMutex = NULL;
		}
	}

	BOOL IsAnotherInstanceRunning(){
		return (ERROR_ALREADY_EXISTS == m_dwLastError);
	}
};
#endif